#ifndef DEFINES_H
#define DEFINES_H

///Max command token length [bytes]
#define 	CMD_SZ 	   20
///Max arg token length [bytes]
#define 	ARG_SZ 	   20
///Max number of arguments for each command
#define 	MAX_ARGS   8
///Standard input fd
#define STDIN 0
///Max length for a single command
#define CMD_BUFF_SZ (MAX_ARGS * (ARG_SZ+1))

/**
* Struct utilized by the server to reply back to the
* client about the result of the received
* notification. 
* 
* Fields:
* 0          8         16          24          32
* [-----ACTION_CODE-----][--RESULT--][-REASON_CODE
* -----------]
*
* ACTION_CODE is the code that identifies the action
* to be executed
*
* RESULT specifies if the action was accepted by the
* server - VALUES: 1 (ack), 0 (nack);
*
* REASON_CODE is optional and *can* be used only when
* the RESULT is negative, to explain the reason why
* the action was refused by the server
* 
* The role of the REASON_CODE, is that, for instance, 
* there could be a subset of actions that cannot be
* accepted by the server, but other that could be,
* if the client knew.
* For instance, we could have a wifi board that does
* not support more than 11Mbps (b mode only), so the
* presence of a reason could prevent the client from
* assuming that the server simply cannot change 
* rate, and make it understand that server only works
* in b mode.
*/
typedef struct {
  unsigned short action;
  unsigned char result;
  unsigned short reason;
} __attribute__((packed)) ctrl_ack;

///Parser recognized commands 
typedef enum{
  OPENCTRL,
  CLOSECTRL,
  OPENDATA,
  CLOSEDATA,
  SET,
  SLEEP,
  SEND,
  UNKNOWN_CMD
} cmd_type;

///Command failure reason codes
typedef enum{
  OPENCTRL_OK
} openctrl_reason;

typedef enum{
  CLOSECTRL_OK
} closectrl_reason;

typedef enum{
  OPENDATA_OK,
  OPENDATA_NOWIFI
} opendata_reason;

typedef enum{
  CLOSEDATA_OK
} data_reason;

typedef enum{
  SET_OK,
  SET_UNKNOWN,
  SET_UNAV_FEAT,             //Unavailable feature
  SET_UNAV_WIFI_CH,          //Unavailable channel
  SET_UNAV_WIFI_RATE        //Rate not supported
}set_reason;

typedef enum{
  SLEEP_OK
}sleep_reason;

typedef enum{
  SEND_OK
}send_reason;

// "##...##" preprocessor operator to glue arguments together.
#define REASON(CMD,REASON) CMD##_##REASON

#endif
